package main

import (
	"fmt"
	"os"
	"time"

	"github.com/BurntSushi/toml"
)

type payToml struct {
	Key  string //密钥
	Post string //Post通知信息，为空不提交，并用本地做服务器
}

var tomlPath string = "./order.toml"
var tomlInfo *payToml

//WriteToml ...
func (T *payToml) WriteToml() {
	f, err := os.Create(tomlPath)
	if err != nil {
		fmt.Println(err)
		return
	}
	if err := toml.NewEncoder(f).Encode(T); err != nil {
		fmt.Println(err)
		return
	}
}
func ReadToml() {
	if _, err := os.Stat(tomlPath); err != nil {
		s := payToml{"password", ""}
		s.WriteToml()
	}
	if _, err := toml.DecodeFile(tomlPath, &tomlInfo); err != nil {
		fmt.Println("请检查配置文件！")
		time.Sleep(time.Second)
		panic(err)
	}
}
